

package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.Condonacion;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


public class CondonacionDelegate {
 private CondonacionFacadeLocal local;

    public CondonacionDelegate() {
        local= lookupCondonacionFacade();
    }

    private CondonacionFacadeLocal lookupCondonacionFacade() {
        try {
            Context c = new InitialContext();
            return (CondonacionFacadeLocal) c.lookup("java:comp/env/CondonacionFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
 public void crear(Condonacion condonacion) throws Exception {
        try {
            local.create(condonacion);
        } catch (Exception e) {
            local = lookupCondonacionFacade();
            throw new Exception("Crear Condonacion. " + e.getMessage());
        }
    }

    public void editar(Condonacion condonacion) throws Exception {
        try {
            local.edit(condonacion);
        } catch (Exception e) {
            local = lookupCondonacionFacade();
            throw new Exception("Editar Condonacion. " + e.getMessage());
        }
    }

    public void eliminar(Condonacion condonacion) throws Exception {
        try {
            local.remove(condonacion);
        } catch (Exception e) {
            local = lookupCondonacionFacade();
            throw new Exception("Eliminar Condonacion. " + e.getMessage());
        }
    }
    public Condonacion buscar(long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupCondonacionFacade();
            throw new Exception("Buscar Condonacion. " + e.getMessage());
        }
}
    }
